package me.zhengjie.util;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component
@PropertySource("classpath:PLCAddress.properties")
@Data
public class PropertySourceConfig {
    @Value("${2}")
    private String device2;
    @Value("${1}")
    private String device1;
    @Value("${192.168.5.10}")
    private String ip1;
    @Value("${192.158.5.123}")
    private String ip2;
    @Value("${today}")
    private String today;
    @Value("${taskNumInOneDay}")
    private int taskNumInOneDay;

    public String getMachineNumByIP(String ip) {
        String machineNum = "";
        switch(ip) {
            case "192.168.5.10":
                machineNum = getIp1();
                break;
            case "192.158.5.123":
                machineNum = getIp2();
            default:
                break;
        }
        return machineNum;
    }

    public String getDeviceIp(int machineNum) {
        String ip = null;
        switch (machineNum) {
            case 1:
                ip = getDevice1();
                break;
            case 2:
                ip = getDevice2();
                break;
            default:
                ip = null;
                break;
        }
        return ip;
    }

}
